Saskia A. Otto
Postdoctoral Researcher
Screenshot of Harvard Business Review website, taken November 11, 2017.
R is a programming language
"R is a system for statistical computation and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories by John Chambers and colleagues. R can be considered as a different implementation of S…..R is available as Free Software under the terms of the Free Software Foundation’s GNU General Public License in source code form. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS."
(from http://r-project.org/)
Directly from the website https://cran.r-project.org
attach()
.<-
(do not use "=")Put a space
In its most basic form, R can be used as a simple calculator.
Consider the following arithmetic operators:
+
-
*
/
^
Consider the following arithmetic operators:
+
-
*
/
^
5 + 5
5 - 5
3 * 5 + 2
(5 + 5) / 2
Consider the following arithmetic operators:
+
-
*
/
^
5 + 5
## [1] 10
5 - 5
## [1] 0
3 * 5 + 2 # multipl. then add.
## [1] 17
(5 + 5) / 2 # add. then div.
## [1] 5
It also has functions that let you do more sophisticated manipulations, which you can combine by using parentheses:
a <- c(1,2,3,4)
c <- (a + sqrt(a))/(exp(2)+1)
It also has functions that let you do more sophisticated manipulations, which you can combine by using parentheses:
a <- c(1,2,3,4)
c <- (a + sqrt(a))/(exp(2)+1)
Order of calculations (from the innermost to outermost parenthesis - just like a calculator).
sqrt(a)
and exp(2)
a
added to sqrt(a)
and 1
added to exp(2)
If your prompt turns into a "+", R thinks you haven't finished your previous command. Either finish the command, or press escape.
sum()
, which takes the elements it should sum over as argument: Getting help for a specific function:
help("mean")
?mean
Search the help pages:
??mean
help.search("mean")
List all functions, which contain "mean":
apropos("mean")
mean
mean
Open a new script in your R Studio Server environment and save it before you start writing anything. Now calculate the following and write the result in the boxes below:
sqrt()
function).R calculates first *
and /
before +
and -
operations. To change the order wrap the respective parts in parentheses!
1.The substraction needs to be in parenthesis otherwise 10 is multiplied with 2 first: ((23 - 10) * 2
2.Wrap now everything in brackets (parentheses) before you divide by 5:
((23 - 10) * 2 + 100) / 5
3.The sqrt()
function comes last and wraps everything else up, that means you write all other calculations inside the function:
sqrt((10 - 23) * -10)
or you use 2 steps:
x <- (10 - 23) * -10)
and then sqrt(x)
For more information contact me: saskia.otto@uni-hamburg.de
http://www.researchgate.net/profile/Saskia_Otto
http://www.github.com/saskiaotto
This work is licensed under a
Creative Commons Attribution-ShareAlike 4.0 International License except for the
borrowed and mentioned with proper source: statements.
Image on title and end slide: Section of an infrared satallite image showing the Larsen C
ice shelf on the Antarctic
Peninsula - USGS/NASA Landsat:
A Crack of Light in the Polar Dark, Landsat 8 - TIRS, June 17, 2017
(under CC0 license)